﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace hdbankwebservice
{
    public class Hash
    {
        public static string getMD5Hash(string source)
        {
            MD5CryptoServiceProvider md = new MD5CryptoServiceProvider();
            byte[] arr = md.ComputeHash(Encoding.Unicode.GetBytes(source));
            return ChuyenHeHexan(arr);           
        }
        protected static string ChuyenHeHexan(byte[] arr)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                sb.Append(arr[i].ToString("x2"));
            }

            return sb.ToString();
        }
        public static string getSHA1Hash(string source)
        {
            SHA1 sh = SHA1.Create();
            byte[] arr = sh.ComputeHash(Encoding.Unicode.GetBytes(source));
            return ChuyenHeHexan(arr);
        }
        public static string getSHA256Hash(string source)
        {
            SHA256 sh = SHA256.Create();
            byte[] arr = sh.ComputeHash(Encoding.Unicode.GetBytes(source));
            return ChuyenHeHexan(arr);
        }
        public static string getSHA384Hash(string source)
        {
            SHA384 sh = SHA384.Create();
            byte[] arr = sh.ComputeHash(Encoding.Unicode.GetBytes(source));
            return ChuyenHeHexan(arr);
        }
        public static string getSHA512Hash(string source)
        {
            SHA512 sh = SHA512.Create();
            byte[] arr = sh.ComputeHash(Encoding.Unicode.GetBytes(source));
            return ChuyenHeHexan(arr);
        }
    }
}
